<template>
  <div style="width: 96%;margin: 0 auto">
    <div class="search">
      <div style="margin-left: 16px;margin-top: 10px;">
        <i class="el-icon-s-custom" ></i>
        病例管理
      </div>
      <div class="int">
        <el-form :model="queryParams" ref="queryForm" :inline="true"  label-width="68px">
          <el-form-item label="" prop="userName">
            <input type="text"  placeholder="请输入患者姓名"  v-model="queryParams.custName">
          </el-form-item>
          <el-select v-model="queryParams.sex" placeholder="请选择患者性别" style="margin-left: 20px;width: 225px;"  size="small">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>

          <input type="text"  placeholder="请输入证件号码" v-model="queryParams.certNo">

          <input type="text"  placeholder="请输入手机号" v-model="queryParams.phone">
          <!--        <el-date-picker-->
          <!--          style="width: 225px;height: 30px!important;margin-left: 20px;"-->
          <!--          v-model="time"-->
          <!--          size="small"-->
          <!--          type="daterange"-->
          <!--          range-separator=" "-->
          <!--          start-placeholder="创建日期"-->
          <!--          end-placeholder="">-->
          <!--        </el-date-picker>-->
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 225px;margin-left: 20px;z-index: 10"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>

        </el-form>
      </div>
      <div class="inquire">
        <el-button type="success" style="height: 30px;display: flex;align-items: center;float:left;margin-right: 20px"
                   @click="Querylist">
          <i  class="el-icon-search"></i>
          查询</el-button>
        <el-button style="height: 30px;display: flex;align-items: center;" @click="reset">
          <i  class="el-icon-refresh"></i>
          重置</el-button>
      </div>
    </div>
    <div class="list">
      <el-table
        :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        stripe
        style="width: 100%"
        :row-class-name="tableRowClassName">
        <el-table-column
          prop="createTime"
          label="时间"
          align="center"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="custName"
          align="center"
          label="患者姓名"
          width="130">
        </el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          align="center"
          width="60">
        </el-table-column>
        <el-table-column
          prop="age"
          label="年龄"
          align="center"
          width="100">
        </el-table-column>
        <el-table-column
          prop="certNo"
          label="证件号码"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="phone"
          label="联系方式"
          align="center"
          width="180">
        </el-table-column>
        <el-table-column
          prop="address"
          align="center"
          label="联系地址">
        </el-table-column>
        <el-table-column
          prop="operate"
          align="center"
          label="操作">
          <template slot-scope="scope">
            <i class="el-icon-search" style="margin-left: 20px;color: #4196ff; cursor:pointer;" @click="examine(scope.$index,scope.row)">查看</i>
            <i class="el-icon-delete" style="margin-left: 20px; color: #FD3236; cursor:pointer;" @click="deletes(scope.$index,scope.row)">删除</i>
            <i class="el-icon-plus" style="margin-left: 20px; color: #1BD5B1; cursor:pointer;" @click="addition(scope.$index,scope.row)">添加</i>
            <!--            <el-button-->
<!--              style="margin-left: 20px; width: 80px;height: 32px"-->
<!--              type="warning"-->
<!--              plain-->
<!--              icon="el-icon-upload2"-->
<!--              size="mini"-->
<!--              @click="handleImport"-->
<!--              v-hasPermi="['system:user:import']"-->
<!--            ><i class="el-icon-upload"></i>导入</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div style="position: absolute;right: 40px;bottom: 70px;">
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="Querylist"
        />
      </div>
    </div>
<!--    添加页面-->
    <div class="tian"  v-show="add">
      <div style="width: 100%;height: 50px;background:  #eaeaea;;line-height: 50px">
        <div style="float:left;margin-left: 25px">添加</div>
        <div style="float:right;margin-right: 20px" @click="off">
          <i class="el-icon-close"></i>
        </div>
      </div>
    <div class="add">
      <div class="content">
        <div class="line">
          <div class="one" style="float:left;">就诊日期</div>
          <input type="text"  placeholder="请输入日期"  v-model="Viewlist.createTime">
        </div>
        <div class="line" style="background: #F8F8F8;">
          <div class="one">就诊医院</div>
          <input type="text"  placeholder="请输入医院" v-model="Viewlist.visitHospital">
        </div>
        <div class="line">
          <div class="one">就诊科室</div>
          <input type="text"  placeholder="请输入科室" v-model="Viewlist.visitDepartment">
        </div>
        <div class="line" style="background: #F8F8F8;">
          <div class="one">挂号证件</div>
          <input type="text"  placeholder="请输入证件" v-model="Viewlist.certificateNo">
        </div>
        <div class="line">
          <div class="one">医生职称</div>
          <input type="text"  placeholder="请输入职称" v-model="Viewlist.doctorPosition">
        </div>
        <div class="lines" style="background: #F8F8F8;">
          <div class="one">家族病史</div>
          <input type="text"  placeholder="请输入家族病逝" v-model="Viewlist.familyMedicalHistory">
        </div>
        <div class="lines">
          <div class="one">个人病逝</div>
          <input type="text"  placeholder="请输入个人病逝" v-model="Viewlist.personalMedicalHistory">
        </div>
        <div class="lines" style="background: #F8F8F8;">
          <div class="one">主诉</div>
          <input type="text"  placeholder="请输入主诉" v-model="Viewlist.chiefComplaint">
        </div>
        <div class="lines">
          <div class="one">诊断</div>
          <input type="text"  placeholder="请输入诊断" v-model="Viewlist.diagnosis">
        </div>
        <div class="lines" style="background: #F8F8F8;">
          <div class="one">处方</div>
          <input type="text" placeholder="请输入处方" v-model="Viewlist.prescription">
        </div>
        <div class="lines" style="background: #F8F8F8;">
        </div>
      </div>
    </div>
      <div style="width: 28%;margin: 0 auto;margin-top: 20px;">
        <el-button type="success" round @click="addcase">确认</el-button>
        <el-button type="info" round @click="off">取消</el-button>
      </div>
    </div>
    <!--    查看页面-->
<!--    <div class="check" v-show="checks">-->
<!--      <i class="el-icon-close" @click="off"></i>-->
<!--      <Caseview/>-->
<!--    </div>-->
  </div>
</template>

<script>
  import {Querylist,sickadd,remove,area,addcase} from "../../../api/patiente/patiente";
  import {importTemplate} from "../../../api/drug/drug";
  import {getToken} from "@/utils/auth";
  import Caseview from "./Caseview";
  export default {
    name: 'PatientManagement',
    components: { Caseview },
    data () {
      return {
        checks:false,
        Viewlist:[],
        // 日期范围
        dateRange: [],
        add:false,
        patientgender: '',
        currentPage: 1,
        pagesize: 10,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          custName: undefined,
          certNo: undefined,
          phone: undefined
        },
        fale: false,
        // 总条数
        total: 0,
        forbidden: false,
        labelPosition: 'right',
        options: [{
          value: '0',
          label: '男'
        }, {
          value: '1',
          label: '女'
        }, {
          value: '2',
          label: '其他'
        }],
        formLabelAlign: {},
        rules:{},
        tableData: [{
          sex:''
        }]
      }
    },
    created(){
      this.Querylist()
      // this.area()
    },
    methods: {
      area(){
        area().then(res=>{
          console.log(res)
        }).catch(err=>{
          console.log(err)
        })
      },
      //患者列表/患者查询
      Querylist(){
        Querylist(this.addDateRange(this.queryParams,this.dateRange) ).then(res=>{
          console.log(res.rows)
          this.tableData=res.rows
          this.total =   res.total;
          for (let i = 0 ; i<res.rows.length; i++){
            // console.log(res.rows[i].sex)
            if(res.rows[i].sex === '0'){
              res.rows[i].sex="男"
            }else if(res.rows[i].sex === '1'){
              res.rows[i].sex="女"
            }else if(res.rows[i].sex === '2'){
              res.rows[i].sex="其他"
            }
          }
        }).catch(err=>{
          console.log(err)
        })
      },
      // 删除
      async deletes (index, row) {
        console.log(row.custId)
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          remove(row.custId).then(res => {
            console.log(res)
            this.Querylist()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }).catch(err => {
            console.log(err)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      // 重置
      reset () {
        this.dateRange=[],
          this.queryParams.custName='',
          this.queryParams.sex='',
          this.queryParams.certNo='',
          this.queryParams.phone='',
          this.Querylist()
      },
      // 分頁
      handleSizeChange (val) {
        this.pagesize = val
        console.log(`每页 ${val} 条`)
      },
      handleCurrentChange (val) {
        this.currentPage = val
        console.log(`当前页: ${val}`)
      },
      // 点击查看
      examine(index,row){
        console.log(row.custId)
        this.$router.push({path:'/Caseview',query: {id:row.custId}})
        this.checks = true
      },
      //      添加
      addition(){
        this.add = true
      },
      //添加确认
      addcase(){
        addcase(this.Viewlist).then(res=>{
          console.log(res)
        }).catch(err=>{
          console.log(err)
        })
      },
      // 取消
      off(){
        this.add = false
        this.Viewlist = []
      },
      submit(){
        sickadd(this.formLabelAlign).then(res=>{
          this.fale = false
          console.log(res)
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.Querylist()
          this.$refs.formRef.resetFields()
        }).catch(err=>{
          console.log(err)
        })
      },
      editconceal () {
        this.fale = false
        this.$refs.formRef.resetFields()
      },
      tableRowClassName ({ row, rowIndex }) {
        if (rowIndex === 1) {
          return 'warning-row'
        } else if (rowIndex === 3) {
          return 'success-row'
        }
        return ''
      }
    }
  }
</script>

<style scoped lang="scss">
  .tian{
    width: 600px;
    height: 800px;
    z-index: 10;
    position: absolute;
    top: -35px;
    bottom: 0;
    left: -10%;
    right: 0;
    margin:  auto;
    background: #FFFFFF;
    border: 1px solid #EEEEEE;
    border-radius: 24px;
    overflow: hidden;
  }
  .add{
    width: 500px;
    height: 600px;
    margin: 0 auto;
    margin-top: 50px;
    background: #FFFFFF;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #EEEEEE;

    .one{
      margin-left: 100px;
      margin-right: 20px;
      float: left;
    }
    .line{
      width: 100%;
      height: 60px;
      line-height: 60px;
      input{
        width: 40%;
        border: none;
        outline: none;
        height: 50px;
        font-size: 15px;
        background: rgba(255, 255, 255, 0);
        float: right;
        margin-right: 110px;
        margin-top: 5px;
      }
    }
    .lines{
      width: 100%;
      height: 60px;
      line-height: 60px;
      input{
        width: 40%;
        border: none;
        outline: none;
        height: 50px;
        font-size: 15px;
        background: rgba(255, 255, 255, 0);
        float: right;
        margin-right: 110px;
        margin-top: 5px;
      }
    }
  }
  .check{
    width: 100%;
    height: 98%;
    background: #ffffff;
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    z-index: 10;
    i{
      position: absolute;
      z-index: 11;
      right: 30px;
      top: 30px;
    }
  }
  .submit{
    width: 80px;
    height: 30px;
    background: #009945;
    border-radius: 4px;
    color: #ffffff;
    text-align: center;
    line-height: 30px;
    font-size: 12px;
    float: left;
    cursor:pointer;
  }
  .cancel{
    width: 80px;
    float: left;
    height: 30px;
    border-radius: 4px;
    text-align: center;
    line-height: 30px;
    font-size: 12px;
    border: 1px solid #EEEEEE;
    margin-left: 20px;
    cursor:pointer;
  }
  .redact{
    width: 600px;
    height: 600px;
    background: #FFFFFF;
    box-shadow: 0px 0px 32px 0px rgba(97,97,97,0.1);
    border-radius: 8px;
    position:fixed;
    top: 50%;
    left: 50%;
    margin-left: -300px;
    margin-top: -285px;
    z-index: 10;
    .title{
      width: 100%;
      height: 40px;
      background: #e7e5e5;
      /*background:red;*/
      border-radius: 8px 8px 0px 0px;
    }
  }
  .search{
    width: 100%;
    height: 170px;
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0px 4px 20px 0px rgba(51,51,51,0.08);
    margin-top: 20px;
  }
  .list{
    width: 100%;
    height: 620px;
    background: #ffffff;
    box-shadow: 0px 4px 20px 0px rgba(51,51,51,0.08);
    border-radius: 8px;
    margin-top: 20px;
    overflow: hidden;
    /*.el-table .warning-row {*/
    /*  background: #fdf5e6;*/
    /*}*/

    /*.el-table .success-row {*/
    /*  background: #f0f9eb;*/
    /*}*/
  }
  .int{
    width: 75%;
    float: left;
    input{
      padding: 0px 10px;
      width: 225px;
      height: 30px;
      background: #FFFFFF;
      border: 1px solid #E8E8E8;
      border-radius: 4px;
      margin-left: 20px;
      margin-top:20px;
    }
  }
  .inquire{
    width: 20%;
    height: 50px;
    float: left;
    margin-top: 20px;
  }

</style>
